﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TouchControls.MasterDetailListView
{
    /// <summary>
    /// Interaction logic for MasterDetailList.xaml
    /// </summary>
    public partial class MasterDetailList : Grid
    {
        public MasterDetailList()
        {
            InitializeComponent();
            MasterListBox.SelectionChanged += new SelectionChangedEventHandler(SelectionChanged);
            ReturnButton.Click += new RoutedEventHandler(ReturnButtonClick);
        }

        public ListBox MasterDetailListBox
        {
            get
            {
                return MasterListBox;
            }
        }

        public void HideItemDetail()
        {
            MasterListBox.SelectedIndex = -1;
            VisualStateManager.GoToElementState(this, "HideDetails", true);
        }

        private void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MasterListBox.SelectedIndex != -1)
            {
                VisualStateManager.GoToElementState(this, "ViewDetails", true);
            }
        }

        private void ReturnButtonClick(object sender, RoutedEventArgs e)
        {
            this.HideItemDetail();
        }
    }
}
